/**
 * 版权所有（c）2021. 上海海鼎信息工程股份有限公司，保留所有权利
 */
package com.lovely602.design.behavior.state.demo;

/**
 * 环境类
 *
 * @author lizhixing
 */
public class ThreadContext {

  private ThreadState state;

  ThreadContext() {
    state = new New();
  }

  public void setState(ThreadState state) {
    this.state = state;
  }

  public ThreadState getState() {
    return state;
  }

  public void start() {
    ((New) state).start(this);
  }

  public void getCpu() {
    ((Runnable) state).getCpu(this);
  }

  public void suspend() {
    ((Running) state).suspend(this);
  }

  public void stop() {
    ((Running) state).stop(this);
  }

  public void resume() {
    ((Blocked) state).resume(this);
  }
}
